var dataUrl=null;
$(function () {
    // dataUrl=$("#dataUrl").val();
    dataUrl ="/modules";
    getCorp(2,"construction");
    getCorp(4,"supervisor");
    getCorp(5,"contractor");
    // checkSelect

});
function getPostPerson(corpPropId,corpId,id) {
    var url=dataUrl+"/homepage/findPostDetails?corpPropId="+corpPropId+"&projectId="+$("#projectId").val()+"&corpId="+corpId+
        "&newDate=" + (new Date().getTime());
    $.ajax({
        url: url,
        type: "get",
        dataType: "json",
        success: function (result) {
            var html="";
            if (result != null&&result.length>0) {

                for (var i = 0; i < result.length; i++) {
                    html += " <div class=\"label-group-div\">" +
                        " <label class=\"control-label\"> " + result[i].postNam  + "</label>" +
                        " <span>";
                    if (result[i].personNames != null&&result[i].personNames.length>0) {
                        for (var j = 0; j < result[i].personNames .length; j++) {
                            html +=result[i].personNames[j];
                            html +=",";
                        }
                    }
                    html += "                    </span>" +
                        "                </div>"
                }
            } else {

            }
            $("#"+id).html(html);
        }
    })

}
function checkSelect(corpPropId,corpId,id) {
$("#"+id+"Span").html($("#"+id+"CheckSelect").find("option:selected").text());
    getPostPerson(corpPropId,corpId,id+"PostPerson")
   /* $("#checkSelect").change(function () {debugger
        var spanId=  this.attr("span-id")+"Span";
        $("#"+spanId).html("("+this.text+")")
    });*/
}
function getCorp(corpPropId,id) {
    var url=dataUrl+"/homepage/getCorpList?corpPropId="+corpPropId+"&projectId="+$("#projectId").val()+ "&newDate=" + (new Date().getTime());
    $.ajax({
        url: url,
        type: "get",
        dataType: "json",
        success: function (result) {
            var html="";
            if (result != null&&result.length>0) {
                if(result.length>1){
                    html="(<span id='"+id+"Span'>"+result[0].caption+"</span>)<br/>";
                    html +="<select  id='"+id+"CheckSelect'  span-id='"+id+"'" +
                        "  onchange='checkSelect("+corpPropId+",this.options[this.options.selectedIndex].value,\""+id+"\")'" +
                    " style='width: 165px;height: 20px'                                   >"
                    for (var i = 0; i < result.length; i++) {
                        html += "<option value='" + result[i].id + "'>" + (result[i].caption) + "</option>";
                    }
                    html +=  "</select>";
                }else {
                    html="("+result[0].caption+")";
                }
                $("#"+id+"Name").html(html);
                getPostPerson(corpPropId,result[0].id,id+"PostPerson")
            } else {
                // layer.msg("获取列表信息错误，请联系管理员！");
                html="(空)";
                $("#"+id+"Name").html(html);
            }
        }
    })
}